/*Prepared Using STATA 16: September 16, 2023*/
cap cd "C:\Users\ejm5\Dropbox\Vietnam Election project\2021_Election\Replication"
use "10_Final data - all phases v2_ANON.dta", clear

drop Questionnaire_order respid_A 

*Merge with undergrad major dataset & questionnaire order
merge 1:1 assignedID using "11_Undergrad major recoded.dta" 
merge 1:1 assignedID using "12_Questionnaire_order.dta", generate(merge2) 
merge m:1 origin_A using "14_region.dta", generate(_region) 
destring votingdivision,replace 
merge m:1 votingdivision using "13_ElectoralDistrictsV2.dta", generate(merge3)
replace region=1 if region==2
drop _merge merge2 merge3


/*Label Intercept Interview*/
lab var consent "Gave consent to be surveyed=1"
lab var livingsituation_rs_A "District where respondent was living during intercept interview"
lab var origin_A "Home province at intercept interview"
lab var university "University respondent was attending during intercept interview"
lab var major "Major in Vietnamese at intercept interview"
lab var interviewloc "Location of intercept interview"
lab var livingsituation "Residency status in Ho Chi Minh City at intercept interview" 
lab var livingsituation_rs "District of residency in Ho Chi Minh City at intercept interview" 
lab var birthyear "Birth year"
lab var gender "Gender, Male (Nam); Female (Nữ) (VNese)"
lab var bike_own "Number of bikes owned at intercept interview (VNese)"
lab var motorbike_own "Number of motorbikes owned at intercept interview (VNese)"
lab var car_own "Number of cars owned at intercept interview (VNese)"
lab var truck_own "Number of trucks owned at intercept interview (VNese)"
lab var famingov_non "No family in government=1"
lab var famingov_parents "Parents in government=1"
lab var famingov_uncleaunt "Uncle or aunt in government=1"
lab var famingov_grandparents "Grandparents in government=1"
lab var famingov_siblings "Siblings in government=1"
lab var famingov_cousins "Cousins in government=1"
lab var famingov_friends "Friends in government=1"
lab var selfingov_none "Respondent not in government=1"
lab var selfingov_yu "Respondent in youth union=1"
lab var selfingov_vcp "Respondent in party union=1"
lab var politicsinterest "Interest (hứng thú ) in politics:  Rất (very), Không nhiều (not much), Hơi (a little), Hoàn toàn không (not at all)"
lab var electiondateawareness "Did respondent know election date? đúng (correct), sai (incorrect)"
lab var electionawareness "What does respondent know about election?"
lab var candidateawareness "Did respondent know candidates at intercept?"
lab var candidateawareness_specific "Could respondent name candidates at intercept?"
lab var nextphaseconsent "Respondent agreed to receive election packet during intercept interview"
lab var registereddate_fri "Packet sent by registered mail on Friday=1"
lab var registereddate_sat "Packet sent by registered mail on Saturday=1"
lab var registereddate_sun "Packet sent by registered mail on Sunday=1"


/*Generate Important New Variables for Random Assignment*/

/*Dummy for HCMC*/
generate HCMC=1 if origin_A=="TP Hồ Chí Minh"
replace HCMC=0 if HCMC==.
lab var HCMC "Respondent from Ho Chi Minh City=1"

/*Dummy for electoral district*/
generate votingdivision2=region if HCMC==0
replace votingdivision2=(votingdivision+10) if HCMC==1
lab var votingdivision2 "Electoral district of respondent"
lab var votinglocation "District in which respondent voted"
lab var votingdivision "Voting division ID in HCMC "


/*Re-create STRATA used in sampling fle based on political knowledge and interest*/
egen strata_new=group(polibg politicsinterest_rc)
pwcorr strata strata_new
drop strata_new
lab var strata "Sampling strata based on family in government and political interest (1-6)"
label define strata 1 "No family, no interest" 2 "No family, not much interest" 3 "No family, some interest" 4 "Yes family, no interest" 5 "Yes family, not much interest" 6 "Yes family, some or a lot of interest"
label values strata strata
/*Generate indidividual STRATA dummies*/
tab strata, gen(strata)
lab var strata1 "No family, no interest" 
lab var strata2 "No family, not much interest" 
lab var strata3 "No family, some interest" 
lab var strata4 "Yes family, no interest" 
lab var strata5 "Yes family, not much interest" 
lab var strata6 "Yes family, some or a lot of interest"

*Recoding relevant variables to English
label var respid "Respondent ID"
drop university_id gender_rc 
encode university, gen (university_id)
label define university_id 1 "Bach Khoa University" 2 "University of Science" 3 "University of Social Sciences & Humanities" 4 "University of Economics HCMC" 5 "University of Architecture HCMC" 6 "Open University HCMC" 7 "Banking University HCMC" 8 "University of Pedagogy HCMC" 9 "University of Pharmacy HCMC",replace
label values university_id university_id
encode gender, gen (gender_rc)
label define gender_rc 1 "Male" 2 "Female",replace
label var gender_rc "Gender"
lab var consent "Gave consent to be surveyed=1"


*Generate Political background variable
drop polibg polibg_yes polibg_no
destring famingov_none famingov_parents famingov_uncleaunt famingov_grandparents famingov_siblings famingov_cousins famingov_friends, replace
egen polibg_yes=rmax(famingov_parents famingov_uncleaunt famingov_grandparents famingov_siblings famingov_cousins famingov_friends)
lab var polibg_yes "Has family member in government=1"
gen polibg_no=0 if famingov_none==1
lab var polibg_no "Does not have family member in government=0"
egen polibg=rowtotal(polibg_yes polibg_no)
label define polibg2 0 "No" 1 "Yes"
label val polibg polibg2
label var polibg "Has at least one family member/friend in VCP or VN government?"

*Generate Political status 
drop polistat polistat_yes polistat_no
destring selfingov_yu selfingov_vcp selfingov_none, replace
egen polistat_yes=rmax(selfingov_yu selfingov_vcp)
lab var polistat_yes "Respondent in party or youth union=1"
gen polistat_no=0 if selfingov_none==1
lab var polistat_no "Respondent not in party or youth union=1"
egen polistat=rowtotal(polistat_yes polistat_no)
label define polistat2 0 "No" 1 "Yes"
label val polistat polistat2
label var polistat "Self at least in one VN governmental organization/VCP?"

*Generate Political interest variable
drop politicsinterest_rc
encode politicsinterest, gen(politicsinterest_rc)
replace politicsinterest_rc=3 if politicsinterest_rc==4
label define politicsinterest_rc 1 "None" 2 "Not much" 3 "Some/A good deal",replace
label var politicsinterest_rc "Generally speaking, how much interest do you usually have in politics?"

*Generate Election Awareness variable
drop electiondateawareness_rc
encode electiondateawareness, gen(electiondateawareness_rc)
label define electiondateawareness_rc 1 "No" 2 "Yes",replace
label val electiondateawareness_rc electiondateawareness_rc
label var electiondateawareness_rc "Know what is the exact Election date?"


/*Recoding and labeling of Endline Survey Data*/

*This variable is used for connecting all datasets together*
label var assignedID "Assigned experiment ID" 


*Election_result - used to record when result was announced
label define Election_result 0 "Not yet" 1"Yes"
label var Election_result "Election result announcement"


*Questionnaire_order - used to record when questionnaire order was changed
label define Questionnaire_order 1"Q2 - Q4 only answered if vote in-person and behind Q12" 2 "Q2 - Q4 right after Q1"
label var Questionnaire_order "Questionnaire order"

*P3 - used to record if respondent has participated in Phase 3
label var P3 "Participated in Phase 3?"

*p2_physicaldelivery - used to record physical treatment in phase 2
label var p2_physicaldelivery "Received physical treatment in Phase 2"

*p2_Qrdelivery - used to record digital treatment in phase 2
label var p2_Qrdelivery "No. of times open QR code in Phase 2"

drop pic
drop Q8_recode Q9_recode
drop Q8Q9_recodeconfidence

*Q5
encode Q5, gen (Q5_en)
label define Q5_en 1"I did not vote in the last election" 2"I voted via another person in the last election" 3"I voted in-person in the last election",replace
label values Q5_en Q5_en
label var Q5_en "Please choose the statement that is most applicable to you in last May election"
label var Q5 "Please choose the statement that is most applicable to you in last May election (VNese)"


*Q8
encode Q8, gen (Q8_en)
label define Q8_en 1 "Yes, I remember at least one name of the candidates I voted for" 2 "No, I remember none of the candidates' names",replace
label var Q8_en "Can you name one or more of the candidates you voted for in the last election?"
label var 	Q8b_name_NA_HCM	"	No. of names in HCM in NA	"
label var 	Q8b_name_PC_HCM	"	No. of names in HCM in PC	"
label var 	Q8b_name_NA_origin	"	No. of names in hometown in NA	"
label var 	Q8b_name_PC_origin	"	No. of names in hometown in PC	"
label var 	Q8b_name_NA_others	"	No. of names in other places in NA	"
label var 	Q8b_name_PC_others	"	No. of names in other places in PC	"
label var Q8 "Do you remember candidate's name? (VNese)"

*Q9
encode Q9, gen (Q9_en)
label define Q9_en 1 "Yes, I remember at least one positions of the candidates I voted for" 2 "No, I remember none of the candidates' positions",replace
label var Q9_en "Can you name the positions of one or more of the candidates you voted for?"
label var 	Q9b_pos_NA_HCM	"	No. of positions in HCM in NA	"
label var 	Q9b_pos_PC_HCM	"	No. of positions in HCM in PC	"
label var 	Q9b_pos_NA_origin	"	No. of positions in hometown in NA	"
label var 	Q9b_pos_PC_origin	"	No. of positions in hometown in PC	"
label var 	Q9b_pos_NA_others	"	No. of positions in other places in NA	"
label var 	Q9b_pos_PC_others	"	No. of positions in other places in PC	"
label var Q9 "Do you remember a position that you voted for? (VNese)"

*Q8Q9 - to mark case where our confidence in recoding is low
label define Q8Q9_recodeconfidence 0 "Confident" 2 "Not too confident",replace

*Q6 Q7 Q10 Q11 Q12
drop Q6 Q7 Q10 Q11 Q12
label var	Q7_1	"	I want to exercise my right of suffrage	"
label var	Q7_2	"	I want to contribute to my country	"
label var	Q7_3	"	I want my thoughts and interests to be represented in the VNA	"
label var	Q7_4	"	I was inspired through the state's information about the election	"
label var	Q7_5	"	I am concerned about a particular issue that I want resolved in the VNA	"
label var	Q7_6	"	The government mobilized me to vote	"
label var	Q6_1	"	I don't know about the election	"
label var	Q6_2	"	I didn't have time on the day of the election	"
label var	Q6_3	"	My parents told me that they would vote on my behalf	"
label var	Q6_4	"	I wasn't registered as a voter for the election	"
label var	Q6_5	"	I didn't want to vote	"
label var	Q11_1	"	I do not have a specific reason, and just choose at random	"
label var	Q11_2	"	His/her name was on top of the list	"
label var	Q11_3	"	My parents/relative/friends instructed me to vote for the candidates	"
label var	Q11_4	"	The voting staff instructed me to vote for the candidates	"
label var	Q11_5	"	I know of him/her personally	"
label var	Q11_6	"	I believe he/she will bring personal benefits to me or my immediate family	"
label var	Q11_7	"	I believe he/she will bring about positive changes for myself, my commmunity, and my country	"
label var	Q11_8	"	I believe the candidates would represent the voice, concerns, and interest of mine at the VNA	"
label var	Q11_9	"	His/her professional qualifications (education, experience) appealed to me	"
label var	Q11_10	"	His/her gender appealed to me (male or female)	"
label var	Q11_11	"	His/her age (young or senior)	"
label var	Q11_12	"	His/her race (Kinh or other ethnicities)	"
label var	Q11_13	"	His/her affiliation with a certain agency (Women Union, Youth Union, Communist Party, etc)	"
label var	Q11_14	"	His/her ability to represent me (Ex: the staff currently working at a locality)	"
label var	Q11_15	"	I want to create opportunities for candidates that don't have advantages	"
label var	Q10_1	"	The voting poll is close to my house, which is convenient for me and my family	"
label var	Q10_2	"	The voting day is on Sunday, which is convenient for me and my family	"
label var	Q10_3	"	The election officials are supportive and helpful	"
label var	Q10_4	"	The election information displayed at the polls are comprehensive and insightful	"
label var	Q12_1	"	A voter voting on behalf of many voters (families, friends, etc)	"
label var	Q12_2	"	The principle of 'secret vote' is not respected (no one is allowed to look at your ballot)	"
label var	Q12_3	"	The staff instructs voters to vote for particular candidates	"
label var	Q12_4	"	The staff refuses to provide a new ballot when sb's is broken	"
label var	Q12_5	"	No negative phenomenon	"

*Q2 Q3 Q4
encode Q2, gen (Q2_en)
label define Q2_en 1 "I intend to keep updated on the VNA through the news/highlights on TV" 2"I intend to watch the debates on television/social media platforms" 3 "I do not intend to and I do not have interest in keeping update with the VNA debates", replace
label var Q2_en "After the election, do you plan to watch/observe news on the upcoming VNA meetings?"
label var Q4 "On 0-10, how confident are you that the newly elected VNA will be responsive to your personal policy objectives or those of your community ?"
label var	Q3_1	"	Meeting sessions at the general assembly"
label var	Q3_2	"	Minister hearings sessions"
label var	Q3_3	"	Voting sessions on draft laws"
label var	Q3_4	"	Discussion in specialized/select committees"
label var	Q3_5	"	Vote of confidence for cabinet members"
label var	Q3_6	"	I don't plan on watching/observing"
lab var Q2 "After the election, do you plan to watch/observe news on the upcoming VNA meetings? (VNese)"
lab var Q3 "Which activities do you intend to watch in VNA (VNese)"

*Q14 Q16 Q18
label var	Q14_1	"	State organizations	"
label var	Q14_2	"	Youth Communist Union	"
label var	Q14_3	"	University	"
label var	Q14_4	"	News organization	"
label var	Q14_5	"	KOL	"
label var	Q14_6	"	Nothing at all	"
label var	Q16_1	"	Mainstream online news website	"
label var	Q16_2	"	State's online resources	"
label var	Q16_3	"	State's sms messages	"
label var	Q16_4	"	Offline newspaper	"
label var	Q16_5	"	Television	"
label var	Q16_6	"	Social media	"
label var	Q16_7	"	Leaflet	"
label var	Q16_8	"	Banners	"
label var	Q16_9	"	Public speakers	"
label var	Q18_1	"	Infographic	"
label var	Q18_2	"	General news	"
label var	Q18_3	"	Interview with prominent speakers	"
label var	Q18_4	"	Creative videos	"
label var	Q18_5	"	Traditional photos (with socialist propaganda themes from the state)	"
label var	Q18_6	"	Creative photos	"
label var	Q18_7	"	Online events (hashtag trandes, facebaook avatar campaigns, etc)
label var Q14 "Where do you get information about the elections? (VNese)"
label var Q16 "What type of news sources did you use? (VNese)"
label var Q18 "What type of online sources did you use? (VNese)"

*Q13
encode Q13, gen (Q13_en)
label define Q13_en 1"I do not remember" 2"I did not do any thing related to election prior to voting" 3"I did not do research, but received information from other people about the Election prior to voting" 4 "I did some research on Election and Candidate information prior to voting" 5 "I did a lot of research on Election and Candidate information prior to voting",replace
label var Q13_en "Please select your behavior from the time up to Election date?"
label var Q13 "Please select your behavior from the time up to Election date? (VNese)"

*Q15
encode Q15, gen (Q15_en)
label define Q15_en 1 "News organization" 3 "Nothing at all" 4"Key opinion leaders/celebrity (KOL)" 6"University" 7"State organization" 10 "Youth Communist Union",replace
label var Q15_en "Out of the selected media sources in Q14, which one do you most prefer to see election information? (Select only one)"
label var Q15 "Out of the selected media sources in Q14, which one do you most prefer to see election information? (VNese)"

*Q17
encode Q17, gen (Q17_en)
label define Q17_en 1 "Banners" 2"Offline newspaper" 3"Mainstream online news website" 4"State's online resources" 7"Public speakers" 8"Social media" 10 "State's SMS messages" 11 "Television" 12 "Leaflet", replace
label var Q17_en "Through which media channels in Q16 that you have seen election information?"
label var Q17 "Through which media channels in Q16 that you have seen election information? (VNese)"

*Q19
encode Q19, gen (Q19_en)
label define Q19_en 1"Creative video" 2 "Creative photos" 3"Traditional photos (with socilalist propaganda themes from the state)" 4"Infographic" 6"Interview with prominent speakers" 7 "Online events (hashtag trandes, facebaook avatar campaigns, etc)" 8 "General news", replace
label var Q19_en "What kind of information modes in Q18 did you prefer the most to see on the selected channels? (Select only one)"
label var Q19 "What kind of information modes in Q18 did you prefer the most to see on the selected channels? (VNese)"

*Q20
encode Q20, gen (Q20_en)
label define Q20_en 3 "National Assembly's achievements, duties, roles, etc" 4"Information about legislation to be considered by the VNA " 5"Information about specific candidates" 6"Voting procedures, election laws, logistic information",replace
label var Q20_en "Which information/content did you see the most through the selected channels/sources above?"
label var Q20 "Which information/content did you see the most through the selected channels/sources above? (VNese)"

*Q21
encode Q21, gen (Q21_en)
label define Q21_en 1 "Both email and physical" 2"Via physical" 3"Via email" 4"I did not receieve anything",replace
label var Q21_en "CRUS sent you some information package prior to the Election. You received:"
label var Q21 "CRUS sent you some information package prior to the Election. You received: (VNese)"

lab var Q22 "How did you access the information in the election package (VNese)?"
lab var Q23 "Did you read the information in the election package if you received in person (VNese)?"

*Q24
encode Q24, gen (Q24_en)
label define Q24_en 1 "T1: Civic Duty" 2"T3: Legislative Docket" 3"T2: Candidate Biography",replace
label var Q24_en "Q24. What was the information you recieved about?"
label var Q24 "Q24. What was the information you recieved about? (VNese)"

lab var Q23 "Did you pay attention to the details in the election package if you used QR code (VNese)?"
lab var Q25 "Did you pay attention to the details in the election package if you used oher approach (VNese)?"

*Q26
encode Q26, gen (Q26_en)
label define Q26_en 1 "T1: Civic Education" 2"T3: Legislative Docket" 3"T2: Candidate Biography",replace
label var Q26_en "Q26. What was the information you recieved about?"
label var Q26 "Q26. What was the information you recieved about? (VNese)"

lab var Q27 "Do you have anything else to add? (VNese)"
lab var Q28 "Are you willing to be contacted again (VNese)"

drop treatment_group
generate treatment_group=0 if control==1
replace treatment_group=1 if T1==1
replace treatment_group=2 if T2==1
replace treatment_group=3 if T3==1
lab var treatment_group "Treatment Group"
label define group 0 "Control" 1 "T1: Civic Education" 2 "T2: Candidate Biography"  3 "T3: Legislative Docket",replace
label val treatment_group group
tab treatment_group
lab var control "Control Group=1"

drop age male motorbikes
generate age=2021-birthyear
generate male=1 if gender=="Nam"
replace male=0 if male==.
generate motorbikes=0 if motorbike_own=="Không sở hữu"
replace motorbikes=1 if motorbike_own=="1 chiếc"
replace motorbikes=2 if motorbike_own=="2 chiếc"
replace motorbikes=3 if motorbike_own=="Nhiều hơn 2 chiếc"


*Exposure variable define

gen receive=1
replace receive=0 if p2_physicaldelivery=="Failed"
replace receive=0 if p2_Qrdelivery==0
replace receive=. if P3=="No"
label define map_check 1"True" 0"False",replace
label val receive  map_check
label var receive "Received info pack"

gen correctrecall=0
replace correctrecall=1 if treatment_group==1 & Q24_en==1
replace correctrecall=1 if treatment_group==1 & Q26_en==1
replace correctrecall=1 if treatment_group==2 & Q24_en==3
replace correctrecall=1 if treatment_group==2 & Q26_en==3
replace correctrecall=1 if treatment_group==3 & Q24_en==2
replace correctrecall=1 if treatment_group==3 & Q26_en==2
label define map_check 1"True" 0"False",replace
label val correctrecall map_check
label var correctrecall "Correctly recalled info pack content"

gen aware=0
replace aware=1 if Q21_en!=4
label val aware map_check
label var aware "Aware of having received info pack"

*Outcome variables
*outcome 1

gen Vote=0
replace Vote=1 if Q5_en ==3|Q5_en==2
replace Vote=0 if Q5_en==1
replace Vote=. if Q5_en==.
label var Vote "Voted in last election"
label define YesNo  1 "Yes" 0 "No", replace
label val Vote YesNo

generate vote_directly=1 if Q5_en==3
replace vote_directly=0 if Q5_en==1|Q5_en==2
label var vote_directly "Voted directly (No Proxy)"
label val vote_directly YesNo

*outcome 2
*Name recall
gen	nameNAHCM	=real(Q8b_name_NA_HCM)
label var nameNAHCM "Number of names recalled in National Assembly Election (voted in HCMC)"
gen	namePCHCM	=real(Q8b_name_PC_HCM)
label var namePCHCM "Number of names recalled in People's Council Election (voted in HCMC)"
gen	nameNAorigin	=real(Q8b_name_NA_origin)
label var nameNAorigin "Number of names recalled in National Assembly Election (voted in home province)"
gen	namePCorigin	=real(Q8b_name_PC_origin)
label var namePCorigin "Number of names recalled in People's Council Election (voted in home province)"
gen	nameNAothers	=real(Q8b_name_NA_others)
label var nameNAothers "Number of names recalled in National Assembly Election (voted in other province)"
gen	namePCothers	=real(Q8b_name_PC_others)
label var namePCothers "Number of names recalled in People's Council Election (voted in other province)"

gen nameNA=max(nameNAHCM, nameNAorigin)
gen namePC=max(namePCHCM, namePCorigin)
label var nameNA "Number of names recalled in National Assembly Election"
label var namePC "Number of names recalled in People's Council Election"

*Position recall
gen	posNAHCM	=real(Q9b_pos_NA_HCM)
lab var posNAHCM "Number of positions respondent recalled voting for in VNA Election (voted HCMC)"
gen	posPCHCM	=real(Q9b_pos_PC_HCM)
lab var posPCHCM "Number of positions respondent recalled voting for in PC Election (voted HCMC)"
gen	posNAorigin	=real(Q9b_pos_NA_origin)
lab var posNAorigin "Number of positions respondent recalled voting for in VNA Election (voted home province)"
gen	posPCorigin	=real(Q9b_pos_PC_origin)
lab var posPCorigin "Number of positions respondent recalled voting for in PC Election (voted home province)"
gen	posNAothers	=real(Q9b_pos_NA_others)
lab var posNAothers "Number of positions respondent recalled voting for in VNA Election (voted other province)"
gen	posPCothers	=real(Q9b_pos_PC_others)
lab var posPCothers "Number of positions respondent recalled voting for in VNA Election (voted other province)"

gen posNA=max(posNAHCM, posNAorigin)
gen posPC=max(posPCHCM, posPCorigin)
label var posNA "Number of positions recalled in NA"
label var posPC "Number of positions recalled in PC"

*outcome 3
gen CorrectVoteReason=0
replace CorrectVoteReason=1 if Q11_7=="1"
replace CorrectVoteReason=1 if Q11_8=="1"
replace CorrectVoteReason=. if P3=="No"
label var CorrectVoteReason "Correct voting reason according to PAP"

gen Correct3VoteReason=0
replace Correct3VoteReason=1 if Q11_7=="1"
replace Correct3VoteReason=1 if Q11_8=="1"
replace Correct3VoteReason=1 if Q11_14=="1"
replace Correct3VoteReason=. if P3=="No"
label var Correct3VoteReason "Correct voting reasons with 3 options"

gen RationalVoteReason=0
replace RationalVoteReason=1 if Q11_6=="1"
replace RationalVoteReason=1 if Q11_7=="1"
replace RationalVoteReason=1 if Q11_8=="1"
replace RationalVoteReason=1 if Q11_9=="1"
replace RationalVoteReason=1 if Q11_10=="1"
replace RationalVoteReason=1 if Q11_11=="1"
replace RationalVoteReason=1 if Q11_12=="1"
replace RationalVoteReason=1 if Q11_13=="1"
replace RationalVoteReason=1 if Q11_14=="1"
replace RationalVoteReason=1 if Q11_15=="1"
replace RationalVoteReason=. if P3=="No"
label var RationalVoteReason "Rational voting reasons"

*outcome 4
*all data (non vote/vote indirectly w/o data is coded as 0)
gen VNALegitimacy_all=0
replace VNALegitimacy_all=0 if Q2_en==3
replace VNALegitimacy_all=1 if Q2_en<=2
replace VNALegitimacy_all=. if P3=="No"
label var VNALegitimacy_all "Intention to watch VNA meeting - all data"
label val VNALegitimacy_all YesNo

gen VNALegitimacy_high=0
replace VNALegitimacy_high=0 if Q2_en==3
replace VNALegitimacy_high=1 if Q2_en==2
replace VNALegitimacy_high=2 if Q2_en==1
replace VNALegitimacy_high=. if P3=="No"
label var VNALegitimacy_high "Level of VNA Engagment"
label define scale  2 "Watch TV" 1 "Social Media" 0 "No Watch", replace
label val VNALegitimacy_high scale


*outcome 5
*all data (non vote/vote indirectly w/o data is coded as 0)
gen VNAConfidence_all=real(Q4)
replace VNAConfidence_all=0 if VNAConfidence_all==.
replace VNAConfidence_all=. if P3=="No"
label var VNAConfidence_all "Confidence score for NA - all data"



*Information exposure level
destring Q16_*, replace
egen Noofexposure = rowtotal(Q16_*)
label var Noofexposure "Number of channels exposed to"
replace Noofexposure=1 if Noofexposure==0



*actual voting location
gen ActualVoteLocation=0
replace ActualVoteLocation=1 if nameNAHCM~=0 | namePCHCM~=0
replace ActualVoteLocation=. if P3=="No"
label define ActualVoteLocation 1 "HCM" 0 "Elsewhere"
label val ActualVoteLocation ActualVoteLocation
label var ActualVoteLocation "Actual Vote Location"


*Creating variables for total number of recall
egen Name=rowtotal(nameNA namePC)
label var Name "No. of names recalled"
egen Position=rowtotal (posNA posPC)
label var Position "No. of positions recalled"

label var T1 "T1: Civic Education"
label var T2 "T2: Candidate Biographies"
label var T3 "T3: Legislative Dockets"


gen research=0 
replace research=1 if Q13_en==4
replace research=1 if Q13_en==5
replace research=. if P3=="No"
label val research polibg2
label var research "Research behavior for Election"



generate vote_proxy=1-vote_directly if Vote==1
replace vote_proxy=0 if Vote==0
lab var vote_proxy "Someone else voted on respondent's behalf"
replace electiondateawareness_rc  = electiondateawareness_rc-1


/*Destringing election outcome variables for number of names and number of positions recalled*/
gen constant=1
lab var constant "Constant"
tab major_rc, gen(major)
lab var major_rc "Major ID"
lab define major_rc 1 "Economics/Business" 2 "Science/Technology" 3 "Law/Policy" 4 "Humanities"
label values major_rc major_rc
label var major1 "Economics/Business"
label var major2 "Science/Technology"
label var major3 "Law/Policy"
recast byte polistat
recast byte polibg

/*Recode Number of Candidate Names from Raw Data*/
destring Q8b_name_NA_HCM Q8b_name_NA_origin Q8b_name_NA_others , replace
generate no_names=Q8b_name_NA_HCM
replace  no_names=Q8b_name_NA_origin if no_names==0|no_names==.
replace  no_names=Q8b_name_NA_others if no_names==0|no_names==.
replace no_names=1 if Q8_en==1 & no_names==0
label var no_names "Number of names recalled in National Assembly Election"


/*Recode Number of Candidate Positions from Raw Data*/
destring Q9b_pos_NA_HCM Q9b_pos_NA_origin Q9b_pos_NA_others , replace
generate no_positions=Q9b_pos_NA_HCM
replace  no_positions=Q9b_pos_NA_origin if no_positions==0|no_positions==.
replace  no_positions=Q9b_pos_NA_others if no_positions==0|no_positions==.
replace no_positions=1 if Q9_en==1 & no_positions==0
label var no_positions "Number of positions recalled in National Assembly Election"

lab var Timestamp "Time and date of second interview"
lab var age "Age at intercept interview (2021-birth year)"
lab var male "Male student=1"
lab var motorbikes "Number of motorbikes in family at intercept interview"
lab var origin "Home province"

/*Destring Q11_7*/
foreach x in Q11_1 Q11_2 Q11_3 Q11_4 Q11_5 Q11_6 Q11_7 Q11_8 Q11_9 Q11_10 Q11_11 Q11_12 Q11_13 Q11_14 Q11_15{
    destring `x', replace
	label val `x' YesNo
}



order assignedID respid consent nextphaseconsent treatment_group T1 T2 T3 control strata receive correctrecall aware Vote vote_directly vote_proxy no_names no_positions Q11_7 VNALegitimacy_all VNAConfidence_all HCMC major_rc votingdivision2 age male motorbikes polibg polistat politicsinterest_rc electiondateawareness_rc Questionnaire_order P3 p2_physicaldelivery p2_Qrdelivery Q*

drop n


save "9_election_working.dta", replace
codebookout "7_Codebook_ElectionWorking", replace


